import request from '@/config/axios'
import { TransferReqVO } from '@/api/crm/customer'

// 分配线索
export const distributeClue = async (data: TransferReqVO) => {
  return await request.put({ url: '/crm/clue/distribute', data })
}
// 根据数量分配线索
export const distributeClueNum = async (data) => {
  return await request.put({ url: '/crm/clue/distributeBySize', data })
}
// 批量领取线索
export const receiveClue = async (ids: any[]) => {
  return await request.put({ url: '/crm/clue/receive', params: { ids: ids.join(',') } })
}

// 下载线索公海导入模板
export const importClueTemplate = () => {
  return request.download({ url: '/crm/clue/get-import-template' })
}
// 导入线索公海
export const handleImport = async (formData) => {
  return await request.upload({ url: `/crm/clue/import`, data: formData })
}

// 删除线索公海
export const deleteClueFromPool = async (id: number) => {
  return await request.delete({ url: `/crm/clue/delete-pool?id=` + id })
}
// 批量删除线索公海
export const deleteCluePools = async (arr) => {
  return await request.delete({
    url: `/crm/clue/batch-delete-pool`,
    params: { ids: arr.join(',') }
  })
}

export interface CluePoolVO {
  id: number
  poolName: string
  type: number
  deptIds: string
  userIds: string
}

// 查询线索公海列表
export const getCluePoolPage = async (params) => {
  return await request.get({ url: `/crm/clue-pool/page`, params })
}

// 查询线索公海详情
export const getCluePool = async (id: number) => {
  return await request.get({ url: `/crm/clue-pool/get?id=` + id })
}

// 查询线索公海详情
export const getCluePoolList = async () => {
  return await request.get({ url: `/crm/clue-pool/simple-list` })
}

// 新增线索公海
export const createCluePool = async (data: CluePoolVO) => {
  return await request.post({ url: `/crm/clue-pool/create`, data })
}

// 修改线索公海
export const updateCluePool = async (data: CluePoolVO) => {
  return await request.put({ url: `/crm/clue-pool/update`, data })
}

// 删除线索公海
export const deleteCluePool = async (id: number) => {
  return await request.delete({ url: `/crm/clue-pool/delete?id=` + id })
}

// 获取线索公海规则设置
export const getCluePoolConfig = async (params: any) => {
  return await request.get({ url: `/crm/clue-pool-config/get`, params })
}

// 更新线索公海规则设置
export const saveCluePoolConfig = async (data: ConfigVO) => {
  return await request.put({ url: `/crm/clue-pool-config/save`, data })
}
